<%@ page language="java" contentType="text/html; charset=windows-1256"
	pageEncoding="windows-1256"%>
<%@ page import="java.util.*"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
	content="text/html; charset=windows-1256">

</head>
<body>
<form method="post" action="SaveQuest"> 
	<%
		String titre = (String) request.getAttribute("titre");
		out.print("<center><font size='20'><B>" + titre
				+ "</font></center><BR>");
		
		int nbrQL = (Integer) request.getAttribute("nbrQL");
		out.print("la valeur de NbrQL est : "  + nbrQL + "<BR>");
		out.print("<input type='hidden' name='titre' value='"); out.print(titre+"'/>");
		
		 TreeMap tm=(TreeMap)request.getAttribute("TM");    
		     
			Set keys = tm.keySet();
			int tab[] = new int[tm.size()];
			String[] tabQ=new String[tm.size()];
			//arranger les ordres
			int b = 0;
			
			//remplir le tableau des indices
			for (Iterator i = keys.iterator(); i.hasNext();) {

				String key = (String) i.next();

				int x = key.lastIndexOf('Q');
				String Q=key.charAt(x)+""+key.charAt(x+1);
				String res = "";
				for (int g = 0; g < x; g++) {
					res += key.charAt(g);
				}

				int resf = Integer.parseInt(res);
				tabQ[b]=Q;
				tab[b] = resf;
				b++;
			}
			//arranger le tableau des indices
			for (int j = 0; j < tab.length; j++) {
				int min = j;
				
				for (int i = j + 1; i < tab.length; i++) {
					if (tab[i] < tab[min]) {
						min=i;
					
					}
					
					}
				if (min!=j){
					int tampon=tab[j];
					tab[j]=tab[min];
					tab[min]=tampon;
					String tampon1=tabQ[j];
					tabQ[j]=tabQ[min];
					tabQ[min]=tampon1;
				}
				
				
			}
		//end arranger le tableau des indices
	//*******************************************************************
	String cle="";
	for(int g=0;g<tab.length;g++)
	{
		cle=tab[g]+tabQ[g];
		

			     
		  
		if(cle.endsWith("QL")){	     
		//les questions libres
		
		HashMap ql = (HashMap) request.getAttribute("QL");
		Iterator iterator = ql.entrySet().iterator();
		int L = 0;
		while (iterator.hasNext()) {
			L++;
			Map.Entry entry = (Map.Entry) iterator.next();
			String libre=(String)entry.getValue();
			if(tm.get(cle).equals(libre)){
			
			out.print(entry.getValue() + "<BR>");
			out.print("<input type='text' size=50/><br>");
			out.print("<input type='hidden' value='");out.print(entry.getValue() + "' name='QL");out.print(L + "'/><br>");
			}////end if(value.equals(libre))
		}

	   	out.print("<input type='hidden' name='nbrQL' value='" + nbrQL +"'/>");
		}////end if(key.endsWith("QL"))
			
			
			
		if(cle.endsWith("QM")){	  	
			
			
		// Voir les QM
		int nbrQM = (Integer) request.getAttribute("nbrQM");
		Hashtable lib=(Hashtable)request.getAttribute("QMLibelle");
		Hashtable poss=(Hashtable)request.getAttribute("QMPos");
		     String QM = "QM";
			for (int j = 0; j < nbrQM; j++) {
				int nbrpos = Integer.valueOf((String) request.getParameter("pos" + j)).intValue();
				String quest = j + "";
				String multiple=(String)lib.get(quest);
				if(tm.get(cle).equals(multiple)){
				out.print(multiple + "<BR>");
                                out.print("<input type='hidden' value='");out.print(lib.get(quest) +"' name='");out.print(QM+ quest + "'/>");
				out.print("<input type='hidden' value='");out.print(nbrpos +"' name='");out.print("pos" + j + "'/>");
				for (int k = 0; k < nbrpos; k++) {

					String pos = j + "" + k;
					out.print("<input type='hidden' value='" + poss.get(pos) +"' name='QM");out.print(quest + "res" + k + "'/>");
					out.print("<input type='checkbox'>" + poss.get(pos)
							+ "<BR>");

				}
				}////end if
			}
			out.print("<input type='hidden' name='nbrQM' value='"); out.print(nbrQM+"'/>");
		}////end end if(key.endsWith("QM"))
			
		if(cle.endsWith("QU")){	  
			// Voir les QU
						int nbrQU = (Integer) request.getAttribute("nbrQU");
						Hashtable libU=(Hashtable)request.getAttribute("QULibelle");
						Hashtable possU=(Hashtable)request.getAttribute("QUPos");
						
							for (int j = 0; j < nbrQU; j++) {
								int nbrpos = Integer.valueOf((String) request.getParameter("posbU" + j)).intValue();
								String quest = j + "";
								
								String unique=(String)libU.get(quest);
								if(tm.get(cle).equals(unique)){
						        	out.print("<input type='hidden' value='");out.print(libU.get(quest) +"' name='QU");out.print(quest + "'/>");
				                        	out.print("<input type='hidden' value='");out.print(nbrpos +"' name='");out.print("posU" + j + "'/>");
								out.print(unique + "<BR>");
								
								
								for (int k = 0; k < nbrpos; k++) {

									String pos = j + "" + k;
						out.print("<input type='hidden' value='" + possU.get(pos) + "' name='QU"); out.print(quest + "res" + k + "'/>");
									out.print("<input type='Radio' name='"); out.print(j+"'>" + possU.get(pos)+ "<BR>");

								}
								}////end if
							}
												   
						   	out.print("<input type='hidden' name='nbrQU' value='"); out.print(nbrQU+"'/>");
			
		}////end end if(key.endsWith("QU"))
			 
			
	
		   }////for(int g=0;g<tab.length;g++)
			%>
			
			<input type="submit" value="Enregistrer dans le DB"/>
			<input type="button" value="Voir PDF"/>
			
			</form>
</body>
</html>